#include <string>
#include "atomic.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
#include "../HeadFile/PCS_splitting_5_model.h"


/**** the Constructor ****/
PCS_splitting_5_model::PCS_splitting_5_model( const string &name)
: Atomic( name )
, PCS_splitting_5_stream_DB_1( this->addInputPort( "PCS_splitting_5_stream_DB_1") )
, PCS_splitting_5_stream_DB_3( this->addOutputPort( "PCS_splitting_5_stream_DB_3") )
, PCS_splitting_5_stream_DB_2( this->addOutputPort( "PCS_splitting_5_stream_DB_2") )
{

		
	string tmpval1(MainSimulator::Instance().getParameter( this->description(), "PCS_splitting_5_stream_DB_1_opt_flowrate_val" ));
	string tmpval2(MainSimulator::Instance().getParameter( this->description(), "PCS_splitting_5_stream_DB_2_opt_flowrate_val" ));
	string tmpval3(MainSimulator::Instance().getParameter( this->description(), "PCS_splitting_5_stream_DB_3_opt_flowrate_val" ));

	PCS_splitting_5_stream_DB_1_opt_flowrate_val = str2float(tmpval1);
	PCS_splitting_5_stream_DB_2_opt_flowrate_val = str2float(tmpval2);
	PCS_splitting_5_stream_DB_3_opt_flowrate_val = str2float(tmpval3);

		
		
}


/*** the initFunction ***/
Model &PCS_splitting_5_model::initFunction()
{

		
	count = 0;
	delay = "00:00:00:00";
	passivate();
	return *this;
		
		
}

/*** the externalFunction ***/
Model &PCS_splitting_5_model::externalFunction( const ExternalMessage &msg )
{

			
	if( msg.port() == PCS_splitting_5_stream_DB_1 ){
		PCS_splitting_5_stream_DB_1_flowrate = msg.value();
		holdIn( active, delay);
	}
	return *this;
		
		
}

/*** the internalFunction ***/
Model &PCS_splitting_5_model::internalFunction( const InternalMessage &msg )
{

			
	passivate();
	return *this;
		
		
}

/*** the outputFunction ***/
Model &PCS_splitting_5_model::outputFunction( const InternalMessage &msg )
{

		
	PCS_splitting_5_stream_DB_2_flowrate = PCS_splitting_5_stream_DB_1_flowrate * (PCS_splitting_5_stream_DB_2_opt_flowrate_val / PCS_splitting_5_stream_DB_1_opt_flowrate_val);
	PCS_splitting_5_stream_DB_3_flowrate = PCS_splitting_5_stream_DB_1_flowrate * (PCS_splitting_5_stream_DB_3_opt_flowrate_val / PCS_splitting_5_stream_DB_1_opt_flowrate_val);
	sendOutput( msg.time(), PCS_splitting_5_stream_DB_2, PCS_splitting_5_stream_DB_2_flowrate);
	sendOutput( msg.time(), PCS_splitting_5_stream_DB_3, PCS_splitting_5_stream_DB_3_flowrate);
	return *this;
		
		
}

